/*
 * @Description:
 * @Author: py
 * @Date: 2024-08-07
 */
import type { OptionsType } from 'plus-pro-components'

export function useDicts() {
    const oOrderStatus = {
        0: '待付款',
        1: '待发货',
        2: '待收货',
        3: '已完成',
        4: '已关闭',
        5: '超时未支付',
        6: '已取消',
    }
    const oAfterSaleType = {
        0: '仅退款',
        1: '仅换货',
        2: '退货退款',
    }
    const oPayType = {
        0: '未支付',
        1: '微信支付',
        2: '支付宝支付',
    }
    const oRefundStatus = {
        0: '商家待处理',
        1: '商家待发货',
        2: '商家发货',
        3: '买家待发货',
        4: '买家发货',
        5: '商家收货',
        6: '买家收货',
        7: '退款中',
        8: '退款成功',
        9: '售后成功',
    }
    const dicts = {
        oAfterSaleType,
        oOrderStatus,
        oPayType,
        oRefundStatus,
    }

    const getDictLabel = (mapKey: string, dicKey: number | string) => {
        if (mapKey in dicts) {
            return dicts[mapKey][dicKey]
        }
        else {
            return ''
        }
    }

    const getDictOptions = (mapKey: string) => {
        if (mapKey in dicts) {
            const targetMap = dicts[mapKey]
            const dictOptions = Object.entries(targetMap).map(([key, val]) => ({
                label: val,
                value: key,
            }))
            return dictOptions as OptionsType
        }
        else {
            return []
        }
    }

    return { getDictLabel, getDictOptions }
}
